package org.dhbw.jee.business.db;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 * The persistent class for the role database table.
 * 
 */
@Entity(name = "ROLE")
@NamedQueries({
	@NamedQuery(name = Role.GETALL, query = "SELECT r FROM ROLE r"),
})
public class Role implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String GETALL = "Role.findAll";

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="ID")
	private
	int id;

	@Column(name="NAME")
	private String name;

	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
	private List<User> users;

	public Role() {
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<User> getUsers() {
		return this.users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public User addUser(User user) {
		getUsers().add(user);
		user.setRole(this);
		return user;
	}

	public User removeUser(User user) {
		getUsers().remove(user);
		user.setRole(null);

		return user;
	}

	public int getId() {
		return id;
	}


}